package com.lyx.controller;

import com.lyx.domain.Product;
import com.lyx.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/*产品控制*/
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService iProductService;

    //保存产品
    @RequestMapping("/save.do")
    public String save(Product product ) throws Exception {
        iProductService.save(product);
        return "redirect:findAll.do";
    }


    //查询全部产品
    @RequestMapping("/findAll.do")  //设置调用路径
    //@RolesAllowed("ADMIN")          //设定访问权限
    public ModelAndView findAll() throws Exception {
        ModelAndView mv=new ModelAndView();
        List<Product> ps=iProductService.findAll();
        //把结果存到mv对象中
        mv.addObject("productList",ps);
        //设定跳转页面
        mv.setViewName("product-list");
        return mv;
    }
}
